package pl.edu.agh.strategies;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import pl.edu.agh.model.core.Price;

import java.util.LinkedList;
import java.util.List;

@Component
public class BuyAndHold implements Strategy {
    private Logger logger = Logger.getLogger(BuyAndHold.class);

    public List<Price> play(double initialMoney, List<Price> prices){
        if(prices == null || prices.size() == 0){
            logger.info("Aborting play due to wrong prices.");
            return prices;
        }

        logger.info("Starting play on " + prices.size() + " prices.");

        // buy
        double stocks = initialMoney / prices.get(0).getClose();

        // hold - income from selling each day
        for(Price price: prices){
            price.setIncome(stocks * price.getClose());
            logger.trace("Income for " + price.getClose() + " is " + price.getIncome());
        }
        return prices;
    }

    @Override
    public String getAllTimeBest() {
        return "Buy & Hold";
    }

    @Override
    public double getBestFitness() {
        return 0.0;
    }

    @Override
    public double getTotalWon() {
        return 0.0;
    }
}